<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="p" uri="/WEB-INF/tld/privilege.tld"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%     
	String path = request.getContextPath();     
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";     
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>修改费用详情</title>
<base href="<%=basePath%>" />
<%@ include file="../../cuv_include.jsp"%>
<style type="text/css">
fieldset,legend,form,table,tr,td,textarea {
	margin: 0;
	padding: 0
}

table {
	margin: 10px 10px
}

;
td {
	line-height: 40px;
}

label {
	font-weight: bold;
}

input[type="text"] {
	width: 250px;
}

input[type="password"] {
	width: 250px;
}

input[type="textarea"] {
	width: 250px;
	overflow-y:auto;
}

input[type="button"]{
	width:80px;
}

input[type="submit"]{
	width:80px;
}

textarea {
	width: 250px;
	overflow-y:auto;
}
</style>

<script type="text/javascript">
    	$(document).ready(function(){
    		var options = {dataType: 'json', beforeSubmit: beforeSubmit, success: process};
    	    $("#costForm").submit(function(){
    	    	$("#btn_modify").attr("disabled", "disabled");
    	    	$(this).ajaxSubmit(options);
    	    	return false;
    	    });
			
    	    var replyoptions = {dataType: 'json', beforeSubmit: beforReplySubmit, success: replyProcess};
    	    $("#replyForm").submit(function(){
    	       $("#btn_reply").attr("disabled", "disabled");
    		   $(this).ajaxSubmit(replyoptions);
    		   return false;
    		});
      	    $("#p_error").hide();
      	    
      	    $("#btn_actual").click(function(){
      	    	$("btn_actual").attr("disabled", "disabled");
      	    	if(confirm("确定结项吗？") != 1) return;
      	    	
      	    	var id = $("#id").val();
      	    	var actualCost = $("#actualCost").val();
      	    	var actualDesc = $("#actualDesc").val();
      	    	var wipeoutUser = $("#wipeoutUser").val();
      	    	var remark = $("#remark").val();
        		$.post("pjcost/cost/modifyactual.do", {id:id, actualCost:actualCost, actualDesc:actualDesc, wipeoutUser:wipeoutUser, remark:remark}, function(data) {
        			$("btn_actual").removeAttr("disabled");
        			var result = $.parseJSON(data);
        			if(result.code == 1) {
        				alert("记录结项成功!");
        				var qs = $("#qs").val();
                		location.href="<%=basePath%>pjcost/cost/userlist.do?"+ qs;;
        			} else {
        				alert(result.message);
        			}
        		});
      	    });
    	});
    	
    	function beforeSubmit() {
            if(isEmpty($("#applyReason").val())) { 
            	alert("申请理由不能为空！" + $("#applyReason").val()); 
            	$("#btn_modify").removeAttr("disabled");
            	return false; 
            }
            return true;
    	}

        function process(responseJson) {
          $("#btn_modify").removeAttr("disabled");
          if(responseJson.code == 0) {
              $('#error_label').text("错误信息：" + responseJson.message);
              $("#p_error").show();
              return;
          }
          var qs = $("#qs").val();
          location.href="<%=basePath%>pjcost/cost/userlist.do?" + qs;
        }
        
        function beforReplySubmit(){
        	if(isEmpty($("#content").val())) {
        		alert("回复内容不能为空！");
        		$("#btn_reply").removeAttr("disabled"); 
        		return false; 
        	}
            return true;
        }
        
        function replyProcess(responseJson){
        	$("#btn_reply").removeAttr("disabled");
        	var str = "<div style='word-wrap:break-word; word-break:normal; margin: 10px 0 0 0; line-height: 1.6;'>"+
     		responseJson.createtime+"&nbsp;&nbsp;<font color='red'>"+responseJson.username+"</font>："+
     		"<span style='color:#00A;'>"+responseJson.content+"</span></div>";
	        $("#commentSet").prepend(str);
	  		$("#content").val("");
        }
    </script>
</head>

<body>
<div style="width: 1208px;">
	<input id="qs" name="qs" type="hidden" value="${qs}" />
	<div style="float:left;">
		<form id="costForm" method="post" action="pjcost/cost/usermodify.do">
			<p id="p_error" style="margin: 10px 10px;">
				<label id="error_label" style="color: red;"></label>
			</p>
			<table>
				<tr>
					<td><label for="id">ID：</label></td>
					<td><input type="text" name="id" id="id" readonly="readonly"
						value="${cost.id }" /></td>
				</tr>
				<tr>
					<td><label for="applyUser">申请人：</label></td>
					<td><input type="text" name="applyUser" readonly="readonly"
						id="applyUser" value="${recordApplyUser.cnname }" /> <font
						color="red">&nbsp;*&nbsp;&nbsp;</font></td>
				</tr>
				<tr>
					<td><label for="province">省份</label></td>
					<td><select id="province" name="province"
						style="width: 120px;"
						<c:if test="${cost.status != 0 }">disabled="disabled"</c:if>>
							<c:forEach items="${provinces}" var="entry" varStatus="status">
								<option
									<c:if test="${entry.key == cost.province }">selected = "true"</c:if>>${entry.value}</option>
							</c:forEach>
					</select> <font color="red">&nbsp;*&nbsp;&nbsp;</font></td>
				</tr>
				<tr>
					<td><label for="applyReason">申请理由</label></td>
					<td valign="top">
						<textarea name="applyReason" id="applyReason" cols="34" rows="10"
								<c:if test="${cost.status != 0 }">disabled="true"</c:if>><c:out value="${cost.applyReason }" /></textarea>
						<font color="red">&nbsp;*&nbsp;&nbsp;</font>
					</td>
				</tr>
				<tr>
					<td><label for="expectCost">预算金额：</label></td>
					<td><input type="text" name="expectCost" id="expectCost"
						value="${cost.expectCost }"
						onkeyup="this.value=this.value.replace(/[^0-9\.]/gi,'')"
						<c:if test="${cost.status != 0 }">disabled="true"</c:if> />
						<font color="red">&nbsp;*&nbsp;&nbsp;</font></td>
				</tr>
				<tr>
					<td><label for="actualCost">实际总额：</label></td>
					<td><input type="text" name="actualCost" id="actualCost"
						value="${cost.actualCost }"
						onkeyup="this.value=this.value.replace(/[^0-9\.]/gi,'')"
						<c:if test="${cost.status != 3}">disabled="true"</c:if> /></td>
				</tr>
				<tr>
					<td valign="top"><label for="actualDesc">实际细项描述：</label></td>
					<td>
					<textarea name="actualDesc" id="actualDesc" cols="34" <c:if test="${cost.status != 3}">disabled="true"</c:if>rows="4" ><c:out value="${cost.actualDesc }" /></textarea></td>
				</tr>
				<tr>
					<td valign="top"><label for="wipeoutUser">报销人：</label></td>
					<td><input type="text" name="wipeoutUser" id="wipeoutUser"
						value="${cost.wipeoutUser } "
						<c:if test="${cost.status != 3 }">disabled="true"</c:if> />
					</td>
				</tr>
				<tr>
					<td valign="top"><label for="remark">备注信息：</label></td>
					<td valign="top">
					<textarea name="remark" id="remark" cols="34" rows="5" <c:if test="${cost.status ==5}">disabled="true"</c:if>><c:out value="${cost.remark } " /></textarea></td>
				</tr>
				<tr>
						<td><label for="checkstatus">审核详情：</label></td>
						<td valign="top"><textarea name="checkStatus"
								id="checkStatus" cols="34" rows="4" disabled="disabled"><c:out value="${recordMap[cost.id] } " />
							</textarea></td>
					</tr>
				<tr>
					<td></td>
					<td><p:chkPri actionUrl="pjcost/cost/usermodify.do">
							<input id="btn_modify" type="submit" value="修改" 
								<c:if test="${cost.status == 5 or cost.status == 3 }">disabled="true"</c:if>
							 />
						</p:chkPri> 
						<p:chkPri actionUrl="pjcost/cost/modifyactual.do">
						<input id="btn_actual" type="button" value="结项"
							<c:if test="${cost.status != 3}">disabled="true"</c:if>/> 
						</p:chkPri>
						<input type="button" id="btn_back" value="返回" onclick="history.go(-1);"/>
					</td>
				</tr>
			</table>
		</form>
	</div>
	<div style="float:left;">
		<div id="commentSet" style="width:500px; margin:20px 0 0 50px;">
		<c:forEach items="${comments }" var="comment" varStatus="status">
			<div style="word-wrap:break-word; word-break:normal; margin: 10px 0 0 0; line-height: 1.6;">
         		<fmt:formatDate value="${comment.createTime}" type="both" dateStyle="medium" timeStyle="medium" />
         			&nbsp;&nbsp;<font color="red">${comment.userCnname}</font>：
		 		<span style="color:#00A;">${comment.content}</span>
         	</div>
		</c:forEach>
		</div>
		<form id="replyForm" action="pjcost/cost/reply.do" method="post">
			<table style="margin:20px 0 0 50px;">
				<tr>
					<td valign="top"><label for="newreply">新回复：</label></td>
					<td valign="top"><textarea name="content" id="content" cols="40" rows="3"><c:out value="${newreply.content }"></c:out></textarea> 
					<input type="text" id="costId" name="costId" class="text"
						value="${cost.id}" style="display: none;" /></td>
				</tr>
				<tr>
					<td></td>
					<td>
						<p:chkPri actionUrl="pjcost/cost/reply.do">
						<input type="submit" id="btn_reply" value="提交"/>
						</p:chkPri>
					</td>
				</tr>
			</table>
		</form>
	</div>
</div>
</body>
</html>